package com.tangsm.spring.boot.deferred.result.domain.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import org.springframework.web.context.request.async.DeferredResult;

import java.util.Date;

/**
 * 任务实体类
 *
 * @author tangsm
 */
public class Task {
    /**
     * 任务ID
     */
    private int taskId;

    /**
     * 当前时间
     */
    private Date createTime = new Date();

    /**
     * 延期结果
     */
    private DeferredResult<Result<String>> taskResult;

    public Task() {
    }

    public Task(int taskId, DeferredResult<Result<String>> taskResult) {
        this.taskId = taskId;
        this.taskResult = taskResult;
    }

    public int getTaskId() {
        return taskId;
    }

    public void setTaskId(int taskId) {
        this.taskId = taskId;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public DeferredResult<Result<String>> getTaskResult() {
        return taskResult;
    }

    public void setTaskResult(DeferredResult<Result<String>> taskResult) {
        this.taskResult = taskResult;
    }

    @Override
    public String toString() {
        return "Task{" +
                "taskId=" + taskId +
                ", createTime=" + DateUtil.formatDateTime(createTime) +
                ", taskResult" + "{responseMsg=" + JSONUtil.toJsonStr(taskResult.getResult()) + "}" +
                '}';
    }
}
